﻿using MediatR;
using Yuekao.API.Read.Command;
using Yuekao.Domain.API;
using Yuekao.Domain.BaseReposi;
using Yuekao.Domain.Entitys;

namespace Yuekao.API.Read.CommandHandler
{
    public class GetOfficeHendler : IRequestHandler<GetOfficeCommand, APIPagging<Office>>
    {
        private readonly IBaseRepository<Office> officeRepo;

        public GetOfficeHendler(IBaseRepository<Office> officeRepo)
        {
            this.officeRepo = officeRepo;
        }
        /// <summary>
        /// 科室显示
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<APIPagging<Office>> Handle(GetOfficeCommand request, CancellationToken cancellationToken)
        {
            APIPagging<Office> res = new APIPagging<Office>();
            var office = officeRepo.GetAll();
            res.Code = APIEnum.Success;
            res.PageData = office.ToList();
            res.Data = res.PageData.FirstOrDefault(); // 设置Data属性为第一个元素或默认值
            return res;
        }

    }
}
